/*
package com.tfjybj.itoo.exam.config;

import com.mongodb.MongoClientSettings;
import org.springframework.boot.autoconfigure.mongo.MongoProperties;
import org.springframework.boot.autoconfigure.mongo.MongoPropertiesClientSettingsBuilderCustomizer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import java.util.concurrent.TimeUnit;

*/
/**
 * @author 商俊帅
 * @date 2022/01/08 17:26
 * @link：https://docs.spring.io/spring-boot/docs/2.5.8/reference/html/features.html#features.nosql.mongodb.connecting
 * https://blog.csdn.net/Tang_IT/article/details/121865318?spm=1001.2014.3001.5501
 * 官网解释：
 *  If you have defined your own MongoClient, it will be used to auto-configure a suitable MongoDatabaseFactory.
 *  The auto-configured MongoClient is created using a MongoClientSettings bean.
 *  If you have defined your own MongoClientSettings, it will be used without modification and the spring.data.mongodb properties will be ignored.
 *  Otherwise a MongoClientSettings will be auto-configured and will have the spring.data.mongodb properties applied to it.
 *  In either case, you can declare one or more MongoClientSettingsBuilderCustomizer beans to fine-tune the MongoClientSettings configuration.
 *  Each will be called in order with the MongoClientSettings.Builder that is used to build the MongoClientSettings.
 **//*

@Configuration
public class MongoConfig {

    @Bean
    MongoClientSettings mongoClientSettings() {
        MongoClientSettings.Builder builder = MongoClientSettings.builder();
        builder.applyToConnectionPoolSettings(b -> {
            // 允许的最大连接数。这些连接在空闲时将保留在池中。一旦池耗尽，任何需要连接的操作都将阻塞等待可用连接 默认: 100
            b.maxSize(100);
            // 最小连接数。这些连接在空闲时将保留在池中，并且池将确保它至少包含这个最小数量 默认: 0
            b.minSize(18);
            // 池连接可以存活的最长时间。零值表示寿命没有限制。超过其生命周期的池连接将被关闭并在必要时由新连接替换
            b.maxConnectionLifeTime(0, TimeUnit.SECONDS);
            // 池连接的最大空闲时间。零值表示对空闲时间没有限制。超过其空闲时间的池连接将被关闭并在必要时由新连接替换
            b.maxConnectionIdleTime(5, TimeUnit.MINUTES);
        });
        return builder.build();
    }

    @Bean
    MongoPropertiesClientSettingsBuilderCustomizer mongoPropertiesCustomizer(MongoProperties properties,
                                                                             Environment environment) {
        return new MongoPropertiesClientSettingsBuilderCustomizer(properties, environment);
    }
}
*/
